<template>
  <div>
    <van-nav-bar title="新增地址" left-text="返回" left-arrow @click-left="() => $router.go(-1)" />
    <van-form>
      <van-field v-model="param.name" name="名字" label="名字" placeholder="请输入名字" />
      <van-field v-model="param.phone" name="手机号" label="手机号" placeholder="请输入手机号" />
      <van-field v-model="param.address" name="地址" label="地址" placeholder="请输入地址" />
      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit" size="large" color="blue" :loading="subLoading"
          @click="saveAddress()" :disabled="!canSub">保存</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Notify } from "vant"

export default {
  data() {
    return {
      param: {
        userID:localStorage.getItem("userID"),
        name: '',
        phone: '',
        address: ''
      },
      subLoading: false,
      hasSend:false,
      time:60
    }
  },
  methods: {
    //确认修改
    saveAddress() {
      this.subLoading = true
      this.$axios.post('/users/setAddress', this.param).then(res => {
        if (res.code === 200) {
          Notify({ type: 'success', message: '修改成功' })
          this.$router.replace("/cart");
        } else {
          Notify({ type: 'danger', message: '好像出了点问题' })
        }
        this.subLoading = false
      })
    },
  },
  computed: {
    canSub() {
      return Boolean(this.param.phone && this.param.name && this.param.address)
    },
  }
}
</script>

<style scoped>
</style>
